using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using ACS.Debugger.Core.Interfaces;
using Microsoft.Win32.SafeHandles;

namespace ACS.Debugger.Core.NativeMethods
{
    [StructLayout(LayoutKind.Sequential, Pack = 8), ComVisible(false)]
    public class PROCESS_INFORMATION
    {
        public IntPtr hProcess;
        public IntPtr hThread;
        public int dwProcessId;
        public int dwThreadId;
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 8), ComVisible(false)]
    public class STARTUPINFO
    {
        public int cb;
        public string lpReserved;
        public string lpDesktop;
        public string lpTitle;
        public int dwX;
        public int dwY;
        public int dwXSize;
        public int dwYSize;
        public int dwXCountChars;
        public int dwYCountChars;
        public int dwFillAttribute;
        public int dwFlags;
        public short wShowWindow;
        public short cbReserved2;
        public IntPtr lpReserved2;
        public SafeFileHandle hStdInput;
        public SafeFileHandle hStdOutput;
        public SafeFileHandle hStdError;

    }

    public class Debugging
    {
        [System.Runtime.ConstrainedExecution.ReliabilityContract(
            System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState,
           System.Runtime.ConstrainedExecution.Cer.Success), DllImport("kernel32.dll")]
        public static extern bool CloseHandle(IntPtr handle);

        [DllImport("mscoree.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
        public static extern ICorDebug CreateDebuggingInterfaceFromVersion(
            int iDebuggerVersion,
            string szDebuggeeVersion);

        public static ICorDebug GetDebugger()
        {  
            return CreateDebuggingInterfaceFromVersion(3, "v2.0.50727");
        }

    }
}
